package secondStage.part4.特殊操作流;

import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @ClassName: [PrintWriterDemo]
 * @Description: 字符打印流
 * @Author: [黄劲松]
 * @CreateDate: [2021-04-05]
 * @Version: [v1.0]
 */
/*
4.2打印流
    字符打印流PrintWriter的构造方法:
        PrintWriter(String fileName)
        使用指定的文件名创建一个 新的PrintWriter,而不需要自动执行刷新

    PrintWriter(Writer out, boolean autoFlush)
        创建一个 新的PrintWriter
        out:字符输出流
        autoFlush:一个布尔值,如果为真,则printIn，printf，或format方法将刷新输出缓冲区
 */
public class PrintWriterDemo {
    public static void main(String[] args) throws IOException {
        PrintWriter pw = new PrintWriter("java.txt");

/*        pw.write("hello");
        pw.write("\r\n");//换行
        pw.flush();         //刷新流
        pw.write("world");
        pw.write("\r\n");
        pw.flush();*/

        /*pw.println("hello");//相当于：pw.write("hello");pw.write("\r\n");
        pw.flush();
        pw.println("world");
        pw.flush();*/

        PrintWriter pw1 = new PrintWriter(new FileWriter("java.txt"),true);
//        PrintWriter pw1 = new PrintWriter(new FileWriter("java.txt"),false);
        pw1.println("hello");//相当于：pw.write("hello");pw.write("\r\n");pw.flush();
        pw1.println("world");
        pw.close();
        pw1.close();
    }
}
